<?php
namespace app\controller;

use think\facade\Cache;

class Captcha extends Common
{
	/**
	* 生成验证码
	*
	* @return
	*/
	public function index()
	{
		$captcha = new \Base\Captcha;
		$array = $captcha->create();
		$token = $this->createtoken();
		if (isset($array['key']) == false) {
			return json(['msg' => '操作失败!', 'code' => 403, 'url' => null, 'token' => null]);
		}
		Cache::set($token, $array, 300);
		return json(['msg' => '操作成功!', 'cache'=> env('redis.password', 'file'), 'code' => 0, 'url' => $array['url'], 'token' => $token]);
	}
	
	function createtoken() {
		$str = md5(uniqid(md5(microtime(true)), true));
		$str = sha1($str);
		return $str;
	}
}
